home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / os2 / srefv12i.zip / testurl.cmd < prev    next >
OS/2 REXX Batch file  |  1997-02-28  |  11KB  |  309 lines

  1. /*   */
  2. testurl:
  3.  
  4.  
  5. parse arg ddir0,tempfile,sel,list,verb,uri,user,basedir,workdir,privset,enmadd,transaction,verbose ,servername,host_nickname,homedir
  6.  
  7. list=translate(list, ' ', '+'||'090a0d'x)  /* Whitespace, etc. */
  8.  
  9.  
  10.    call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  11.         call lineout tempfile, "<html><head><title>SRE-Filter: Test a URL </title>"
  12.         call lineout tempfile, "</head><body>"
  13.  
  14. aclient=user
  15. auser=' '
  16. do until list=""
  17.   parse var list food '&' list
  18.   say " food " food
  19.   if abbrev(upper(food),'TESTURL=')=1 then do
  20.      parse  var food foo '=' aurl
  21.      aurl=packur(aurl)
  22.      parse var aurl  aurl2 '?' alist
  23.      aurl2=strip(upper(aurl2),'l','/')
  24.      aurl=strip(aurl2,'l','\')
  25.   end
  26.   if abbrev(upper(food),"TESTCLIENT=")=1 then do
  27.         parse var food '=' aclient
  28.   end
  29.   if abbrev(upper(food),"USERNAME=")=1 then do
  30.         parse var food '=' auser
  31.   end
  32. end
  33.  
  34. if aclient=' ' then aclient=user
  35.  
  36. ahost=reqfield('HOST:')
  37. call lineout tempfile,' <h1> Resolving a Request: Displaying the steps in the process </h1>'
  38. call lineout tempfile,' <em> under construction .... </em> <p>'
  39. call lineout tempfile,' <p> <h3> Basic request data </h3> <ul> <li> The <strong>Host name</strong> specified by your browser is: 'ahost
  40. aservername=servername() ; aserveraddr=extract('serveraddr') ;
  41. aport=extract('serverport')
  42. call lineout tempfile,' <li> The server port is: <b> ' aport '</b> '
  43. call lineout tempfile,'<li> The servername/address assumed by GoServe<b>: ' aservername ',' aserveraddr '</b> '
  44. call lineout tempfile,'<li> The servername nickname assumed by SRE-Filter<b>: ' servername  '</b> '
  45. call lineout tempfile,'<br> ... with a Host_nickname<b>: '  host_nickname '</b> '
  46. call lineout tempfile,'<li> The client IP address assumed by GoServe <b>: ' user '</b> '
  47.  
  48.  
  49. t1=value(enmadd||'PRE_FILTER',,'os2environment')
  50. t2=value(enmadd||'PREFILTER_NAME',,'os2environment')
  51. if t1='YES'  then                
  52.  call lineout tempfile,'<li><strong> Note:</strong> The <code>' t2 ' </code> pre-filter would have been called '
  53.  
  54. call lineout tempfile,'</ul>'
  55.  
  56. aserver=aservername
  57. aurl=aurl2
  58.  
  59. if pos('HTTP://',aurl)>0  then do
  60.    parse var aurl  'HTTP://' aserver '/' aurl
  61. end
  62. call lineout tempfile,' <H3>The URL to be Tested </h3>'
  63. call lineout tempfile,' <ul> <li> The Servername for this test<b>: ' aserver '</b> '  
  64. call lineout tempfile,' <li> The client IP address for this test<b>: ' aclient '</b> '  
  65. call lineout tempfile,'<li> The URL for this test<b>: ' aurl '</b> '  
  66. call lineout tempfile,' <li> The username: <b> ' auser '</b>'
  67. call lineout tempfile,'<li> The argument list<b>: ' alist '</b> '
  68. call lineout tempfile,' </ul> '
  69.  
  70. call lineout tempfile,' The host:  <ul> <li>'
  71. foo=get_Host(aserver)
  72. parse var foo ddir host_nickname
  73. home_dir=get_value('HOME_DIR',host_nickname)      
  74. call lineout tempfile,' </ul>  '
  75.  
  76. call lineout tempfile,' <h3> Client access-rights info </h3> <ul>'
  77. owners=get_value('Owners',host_nickname)
  78. if wordpos(aclient,owners)>0 then
  79.    call lineout tempfile, '<li> Client is an OWNER '
  80. else 
  81.    call lineout tempfile, '<li> Client is NOT an owner '
  82. mdo=sref_badips(aclient,enmadd,host_nickname)
  83. if mdo=1 then
  84.     call lineout tempfile,' <li> Client has an UNALLOWED IP '
  85. else
  86.     call lineout tempfile,' <li> Client does NOT have  an UNALLOWED IP '
  87.  
  88. a1=goodips(aclient)
  89. if a1=0 then
  90.   call lineout tempfile,' <li> Client does not have an inhouse IP '
  91. else 
  92.   call lineout tempfile,' <li> Client has an INHOUSE IP: <b> ' a1 '</b>'
  93. call lineout tempfile,'</ul>'
  94.  
  95.  
  96. call lineout tempfile,' <hr> <H3> Resolving the URL </H3> '
  97. call lineout tempfile,' <ol> '
  98.  
  99.  
  100.  
  101. call lineout tempfile,' <li> The PUBLIC Urls: <menu> <li>'
  102. foo=get_puburl(aurl,host_nickname,ddir)
  103. if foo>0 then signal all_done
  104. call lineout tempfile,'</menu> '
  105.  
  106. all_done:
  107. call lineout tempfile,'</ol>'
  108. call lineout tempfile,' </body> </html> '
  109. call lineout tempfile
  110. 'file erase type text/html name ' tempfile
  111.  
  112.  
  113. return 'done'
  114. exit
  115.  
  116. /***************************/
  117. get_host:procedure expose enmadd  tempfile ddir0
  118. parse arg myaddr,
  119.  
  120. servername=' '
  121. ddir=ddir0
  122. nhosts=value(enmadd||'HOSTS.0',,'os2environment')
  123. host_nickname=' '
  124. /* check on multiple hosts */                                                
  125. if nhosts>0 then do                                                          
  126.    stuff=sref_host_info(myaddr,nhosts,enmadd)                                
  127.    if stuff<>0 then do                                                       
  128.       parse var stuff  servername ',' host_nickname  ',' ddir                
  129.       host_nickname=strip(host_nickname); ddir=strip(ddir)                   
  130.       default=strip(default) ; servername=strip(servername)                  
  131.    end                                                                       
  132. end                                                                          
  133. if servername=0 then do  /* nhosts=0, or no match in get_host_info */        
  134.     ddir=datadir()                                                           
  135.     servername=servername()                                                  
  136.     host_nickname=' '                                                        
  137. end                                                                          
  138.  
  139. call lineout tempfile,' The Host Nickname used for this request: <b> ' host_nickname '</b> '
  140. call lineout tempfile,' <br> ... with data directory <b> : ' ddir '</b> '
  141. call lineout tempfile,' <br> ... and servername <b>: ' servername '</b> '
  142.  
  143. return ddir ' 'host_nickname
  144.  
  145.  
  146. /**************************/
  147. get_puburl:procedure expose tempfile  os2e enmadd
  148. parse arg sel,host_Nickname,ddir
  149.  
  150.   tsel=translate(sel)
  151.   gotit=0 ; doexact=0 
  152.   call get_public_urls(host_nickname)
  153.   do m=1 to public_urls.0
  154.     if public_urls.m=' ' then iterate  
  155.     parse var public_urls.m  purl  isliteral  aname0
  156.     purl=strip(purl) ;
  157.     ares=sref_wildcard(tsel,purl,doexact)
  158.     parse var ares astat "," aurl ;  astat=strip(astat)
  159.     if astat=0 then iterate   /* no match */
  160.     usesel=sel ;
  161.     useliteral=strip(upper(isliteral)) ;  exact_name=strip(aname0)
  162.     gotit=m
  163.     if ares=1 then
  164.        leave           /*first exact match rules */
  165.      else
  166.       doexact=1
  167.   end
  168.  
  169.   if gotit>0 then do        /* if gotit, then reset the sel */
  170.  
  171.     call lineout tempfile,' Matching public_URL is <b> ' public_urls.gotit '</b>'
  172.  
  173. /* if it's a literal public file, minimal processing is required */
  174.      if abbrev(useliteral,"LITERAL")=1 then do
  175.        if exact_name<>"" then do
  176.            call lineout tempfile,' <br> -- With exactname of: <b> ' exact_name '</b>'
  177.            return 2
  178.        end
  179.        else do
  180.            parse var usesel asel '?' .
  181. say " ddir " ddir
  182.            afile=translate(ddir||asel,'\','/')
  183.            if pos('~',afile)>0 then do
  184.               afile=sref_replacestrg(afile,'~',home_dir) ;
  185.            end
  186.            call lineout tempfile,' <br> With literal file name of: <b> ' afile '</b>'
  187.            return 1
  188.        end
  189.      end  /* listeral */ 
  190.      return 0
  191.   end           /* gotit */
  192.   else do
  193.         call lineout tempfile,' No matching public_URLs. '
  194.         return 0
  195.   end
  196.  
  197.  
  198. /* ------------ */
  199. /*  get public urls for this host */
  200. /*----------------*/
  201. get_public_urls:procedure expose public_urls. enmadd os2e 
  202. parse arg hname
  203. os2e='os2environment'
  204.  
  205.  
  206. nin=0 ;n2=0
  207. if hname<>"" then do 
  208.     aa='public_urls.'||hname
  209.     n2=10000
  210. end
  211. do mm=1 to n2
  212.       moe=enmadd||aa||'.'||mm
  213.  
  214.       tt=strip(value(moe,,os2e))
  215.       if tt="" | tt=0 then      leave
  216.       nin=nin+1 ; public_urls.nin=tt
  217. end
  218.  
  219. aa='public_urls'
  220. do mm=1 to 10000
  221.       moe=enmadd||aa||'.'||mm
  222.       tt=strip(value(moe,,os2e))
  223.       if tt="" | tt=0 then leave
  224.       nin=nin+1 ; public_urls.nin=tt
  225. end
  226.  
  227. public_urls.0=nin
  228. return nin
  229.  
  230. /* ----------- */                                                        
  231. /* get environment value, possibly host specific */                      
  232. /* ------------ */                                                       
  233. get_value: procedure expose enmadd host_nickname                          
  234. parse arg vname,hname0
  235. if hname0=0 then 
  236.         hname=' '
  237. else                                                    
  238.     hname=strip(host_nickname)                          
  239.  
  240. vname=strip(vname) ;
  241. if hname<>' ' then do
  242.    booger=strip(enmadd||vname||'.'||hname)
  243.    aval=value(booger,,'os2environment')
  244.    if aval<>' ' Then                                                     
  245.         return aval                                                      
  246. end                                                                      
  247. aval=value(enmadd||vname,,'os2environment')                              
  248. return aval                                                              
  249.  
  250.  
  251. /* -----------------------------------------------------------------------*/
  252. /* see if ip address matches one of a set of good ips (1 if yes)*/
  253. /* -----------------------------------------------------------------------*/
  254. goodips: procedure expose  enmadd  host_nickname
  255.  
  256. parse arg anips
  257.  
  258. os2e='os2environment'
  259.  
  260. anips=strip(anips) ;hostn=strip(host_nickname)
  261. parse var anips ip.1 '.' ip.2 '.' ip.3 '.' ip.4
  262. mm=0 ; ndo=0
  263.  
  264. goodips2:               /* jump here to check default ones */
  265. /* first, get "Host specific" inhouseips */
  266.  aa='inhouseips.' 
  267.  if hostN<>"" then aa='inhouseips.'||hostn||'.'
  268.  nin=0
  269.  do mm=1 to 10000
  270.       useme=enmadd||aa||mm
  271.       tt=strip(value(useme,,os2e))
  272.       if tt="" | tt=0 then leave
  273.       nin=nin+1 ; inhouseips.nin=tt
  274.  end
  275.  inhouseips.0=nin
  276.  
  277. mdo=inhouseips.0
  278. do mm=1 to mdo
  279.   if inhouseips.mm=' '  then iterate
  280.   if inhouseips.mm=anips then do        /*it's an exact match -- extract privset */
  281.       parse var inhouseips.mm uip.1 '.' uip.2 '.' uip.3 '.' uip.4 privset1
  282.       return inhouseips.mm 
  283.   end
  284. end
  285.  
  286. /* if here, try wild card matches */
  287. do m2=1 to mdo           /* wild card matches */
  288.  
  289.      if inhouseips.m2=' ' then iterate
  290.      match=1
  291.      parse var inhouseips.m2 uip.1 '.' uip.2 '.' uip.3 '.' uip.4 privset1
  292.      do mm2 =1 to 4
  293.        if uip.mm2="*" then iterate
  294.        if uip.mm2=ip.mm2 then iterate
  295.        match=0       /*if here, not a match */
  296.        leave
  297.      end
  298.      if match=1 then return inhouseips.m2
  299. end
  300.  
  301. if hostn<>"" then do
  302.    hostn=" "
  303.   signal goodips2
  304. end
  305. return 0                /* no match */
  306.  
  307.  
  308.  
  309.